package xhwl.insurance.adapter;

import android.content.Context;
import android.support.v7.widget.CardView;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;


import com.bumptech.glide.Glide;

import java.util.ArrayList;
import java.util.List;

import xhwl.insurance.R;
import xhwl.insurance.customView.CircleImageView;
import xhwl.insurance.http.bean.resp.ExpertResp;
import xhwl.pulltorefresh.adapter.BaseAdapter;
import xhwl.pulltorefresh.adapter.ViewHolder;

/**
 * Created by fuyi on 2017/11/22.
 */

public class ExpertAdapter extends RecyclerView.Adapter<ExpertAdapter.MyViewHolder> {

    private ExpertAdapter.OnItemClickLitener mOnItemClickLitener;
    private Context mContext;
    private ArrayList<ExpertResp> data;

    public ExpertAdapter(Context mContext, ArrayList<ExpertResp> data) {
        this.mContext = mContext;
        this.data = data;

    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View layout = LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_expert,null);
        return new MyViewHolder(layout);
    }

    @Override
    public void onBindViewHolder(final MyViewHolder holder, final int position) {
        holder.mName.setText(data.get(position).getEXPERT_NAME());
        Glide.with(mContext).load(data.get(position).getSMALL_PIC()).error(R.drawable.xiaoren).into(holder.mHead);


        if (mOnItemClickLitener != null) {
            holder.mExpertItem.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    mOnItemClickLitener.onItemClick(view,position);
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return data.size();
    }


    public class MyViewHolder extends RecyclerView.ViewHolder {

        TextView mName;
        CircleImageView mHead;
        RelativeLayout mExpertItem;

        public MyViewHolder(View itemView) {
            super(itemView);
            mName = (TextView) itemView.findViewById(R.id.tv_expert_name);
            mHead = (CircleImageView) itemView.findViewById(R.id.iv_expert_head);
            mExpertItem = (RelativeLayout) itemView.findViewById(R.id.rl_expert_item);

        }
    }

    public interface OnItemClickLitener {
        void onItemClick(View view, int position);
    }

    public void setOnItemClickLitener(ExpertAdapter.OnItemClickLitener mOnItemClickLitener) {
        this.mOnItemClickLitener = mOnItemClickLitener;
    }

}

